home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’92 / PatchWorks Kit / <PatchWorks++> / GlobalPatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-30  |  1.6 KB  |  77 lines  |  [TEXT/KAHL]

  1. /*
  2.     GlobalPatch.c
  3.     
  4.     Sub-class of TrapPatch that uses the SetTrapAddress available at INIT time
  5.     to patch in every context of the system.
  6.     
  7.     Part of PatchWorks, the Extension Development Framework.
  8.     
  9.     by Mouse Herrell & Patrick Beard.
  10.     
  11.     Permission is granted to use this source code for any purpose, as long
  12.     as the copyright notice is maintained.
  13.     
  14.     © 1992 Berkeley Systems, Inc.
  15.  */
  16.  
  17. #include "GlobalPatch.h"
  18.  
  19. #define GetTrapAddress_Trap 0xA146
  20. #define NGetTrapAddress_Tool 0xA646
  21. #define NGetTrapAddress_OS 0xA246
  22.  
  23. #define SetTrapAddress_Trap 0xA047
  24. #define NSetTrapAddress_Tool 0xA647
  25. #define NSetTrapAddress_OS 0xA247
  26.  
  27. PatchProcPtr GlobalPatch::theirGetTrapAddress;
  28. PatchProcPtr GlobalPatch::theirSetTrapAddress;
  29.  
  30. void GlobalPatch::SaveTrapAddresses()
  31. {
  32.     theirGetTrapAddress = (PatchProcPtr)NGetTrapAddress(GetTrapAddress_Trap, GetTrapType(GetTrapAddress_Trap));
  33.     theirSetTrapAddress = (PatchProcPtr)NGetTrapAddress(SetTrapAddress_Trap, GetTrapType(SetTrapAddress_Trap));
  34. }
  35.  
  36. PatchProcPtr GlobalPatch::Get()
  37. {
  38.     ProcPtr trapAddr;
  39.     Boolean toolTrap = GetTrapType(itsTrap);
  40.     
  41. #ifdef THINK_C
  42.     asm {
  43.         move.w    this->itsTrap, d0
  44.         move.b    toolTrap, d1
  45.         beq.s    @0
  46.         move.w    #NGetTrapAddress_Tool, d1
  47.         bra.s    @1
  48.     @0    move.w    #NGetTrapAddress_OS, d1
  49.     @1    move.l    theirGetTrapAddress, a0
  50.         jsr        (a0)
  51.         move.l    a0, trapAddr
  52.     }
  53. #endif
  54.     
  55.     return trapAddr;
  56. }
  57.  
  58. void GlobalPatch::Set(PatchProcPtr proc)
  59. {
  60.     Boolean toolTrap = GetTrapType(itsTrap);
  61.  
  62. #ifdef THINK_C
  63.     asm {
  64.         move.w    this->itsTrap, d0
  65.         move.l    proc, a0
  66.         move.b    toolTrap, d1
  67.         beq.s    @0
  68.         move.w    #NSetTrapAddress_Tool, d1
  69.         bra.s    @1
  70.     @0    move.w    #NSetTrapAddress_OS, d1
  71.     @1    move.l    theirSetTrapAddress, a1
  72.         jsr        (a1)
  73.     }
  74. #endif
  75.  
  76. }
  77.